package com.hlk.user.controller;

import com.hlk.constant.Constant;
import com.hlk.controller.user.MyFansControllerApi;
import com.hlk.enums.Sex;
import com.hlk.pojo.vo.FansCountsVO;
import com.hlk.pojo.vo.RegionRatioVO;
import com.hlk.result.Result;
import com.hlk.user.service.MyFanService;
import com.hlk.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author hlk
 * @version 1.0
 * @date 2021-01-08 10:49
 */
@RestController
public class MyFansController implements MyFansControllerApi {
    @Autowired
    private MyFanService myFanService;

    @Override
    public Result isMeFollowThisWriter(String writerId, String fanId) {
        boolean res = myFanService.isMeFollowThisWriter(writerId, fanId);
        return Result.ok(res);
    }

    @Override
    public Result follow(String writerId, String fanId) {
        myFanService.follow(writerId, fanId);
        return Result.ok();
    }

    @Override
    public Result unfollow(String writerId, String fanId) {
        myFanService.unfollow(writerId, fanId);
        return Result.ok();
    }

    @Override
    public Result queryAll(String writerId, Integer page, Integer pageSize) {
        if (page == null) {
            page = Constant.PAGE;
        }

        if (pageSize == null) {
            pageSize = Constant.PAGESIZE;
        }
        PageResult result = myFanService.queryAll(writerId, page, pageSize);

        return Result.ok(result);
    }

    @Override
    public Result queryRatio(String writerId) {
        int manCounts = myFanService.queryFansCounts(writerId, Sex.man);
        int womanCounts = myFanService.queryFansCounts(writerId, Sex.woman);

        FansCountsVO fansCountsVO = new FansCountsVO();
        fansCountsVO.setManCounts(manCounts);
        fansCountsVO.setWomanCounts(womanCounts);
        return Result.ok(fansCountsVO);
    }

    @Override
    public Result queryRatioByRegion(String writerId) {
        List<RegionRatioVO> list = myFanService.queryRegionRatioCounts(writerId);
        return Result.ok(list);
    }
}
